package xin.marcher.module.seller.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.seller.domain.dto.SellerInfoResultDTO;
import xin.marcher.module.seller.domain.request.SellerInfoRequest;
import xin.marcher.module.seller.domain.response.SellerInfoResponse;
import xin.marcher.module.seller.service.SellerInfoService;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Slf4j
@RestController
@RequestMapping("/sellerInfo")
public class SellerInfoController {

    @Resource
    private SellerInfoService sellerInfoService;

    /**
     * 新增卖家
     *
     * @param request
     * @return
     */
    @RequestMapping("/saveSellerInfo")
    public JsonResult<SellerInfoResultDTO> saveSellerInfo(SellerInfoRequest request) {
        try {
            SellerInfoResultDTO result = sellerInfoService.saveSellerInfo(request);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    /**
     * 修改卖家
     *
     * @param request
     * @return
     */
    @RequestMapping("/updateSellerInfo")
    public JsonResult<SellerInfoResultDTO> updateSellerInfo(SellerInfoRequest request) {
        try {
            SellerInfoResultDTO result = sellerInfoService.updateSellerInfo(request);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    /**
     * 查询卖家
     *
     * @param request
     * @return
     */
    @RequestMapping("/querySellerInfo")
    public JsonResult<List<SellerInfoResponse>> querySellerInfo(SellerInfoRequest request) {
        try {
            List<SellerInfoResponse> responseList = sellerInfoService.querySellerInfo(request);
            return JsonResult.buildSuccess(responseList);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

    /**
     * 删除卖家
     *
     * @param sellerIdList
     * @return
     */
    @RequestMapping("/deleteSellerInfo")
    public JsonResult<SellerInfoResultDTO> deleteSellerInfo(List<Integer> sellerIdList) {
        try {
            SellerInfoResultDTO result = sellerInfoService.deleteSellerInfo(sellerIdList);
            return JsonResult.buildSuccess(result);
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(sellerIdList), e);
            return JsonResult.buildError(e.getMessage());
        }
    }

}
